/**
 * Created by SunLunatic on 2015/4/3.
 */
var common = require("../util/common");
var fs = require('fs');
var path = require('path');
var util = require('util');

exports.uEidtor = function(req, res) {
    if (req.query.action === 'uploadimage') {
        var upfile = req.files.upfile;
        var newFileName = common.genid() + "." + upfile.name.split(".")[1];

        var readStream = fs.createReadStream(upfile.path)
        var writeStream = fs.createWriteStream("/work/sun/resource/img/"+newFileName);

        readStream.pipe(writeStream);

        res.json({
            'url': "http://" + common.getServer() + "/img/" + newFileName,
            'state': 'SUCCESS',
            'title': 'demo.jpg',
            'original': 'demo.jpg'
        });
    } else {
        res.setHeader('Content-Type', 'application/json');
        res.redirect('/plugin/ueditor1_4_3-utf8-jsp/jsp/config.json');
    }
}
